//
//  SingerSongsViewController.m
//  LuckyRadio
//
//  Created by Mr、J on 15/11/25.
//  Copyright © 2015年 chenjun. All rights reserved.
//

#import "SingerSongsViewController.h"
#import "CustomerNetworking.h"
#import <UIImageView+WebCache.h>
#import "SongsModel.h"

#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width

#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

#define WIDTH_PRO(X) (X)*(SCREEN_WIDTH/375)

#define HEIGHT_PRO(Y) (Y)*(SCREEN_HEIGHT/667)
@interface SingerSongsViewController ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>

@property (nonatomic, retain) UIImageView *headImage;

@property (nonatomic, retain) UITableView *collectionView;

@property (nonatomic, retain) UILabel *titleLabel;

@property (nonatomic, retain) UIImageView *tagImageView;

@property (nonatomic, retain) UILabel *nameLabel;

@property (nonatomic, retain) UILabel *numLabel;

@property (nonatomic, retain) UIButton *playAllBtn;

@property (nonatomic, retain) UIImageView *playImage;

@property (nonatomic, retain) UILabel *playLabel;

@property (nonatomic, retain) UILabel *tagLabel;

@property (nonatomic, retain) NSMutableArray *songsArray;

@property (nonatomic, retain) UIView *totalView;

@property (nonatomic, retain) UIView *ButtonView;

@end

@implementation SingerSongsViewController
- (void)dealloc
{
    [_titleLabel release];
    [_tagImageView release];
    [_nameLabel release];
    [_numLabel release];
    [_playAllBtn release];
    [_playImage release];
    [_playLabel release];
    [_tagLabel release];
    [_songsArray release];
    [_headImage release];
    [_collectionView release];
    [_totalView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.songsArray = [NSMutableArray array];
    [self loadData];
    [self createSubViews];
    
}

-(void)createSubViews
{
    self.totalView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, HEIGHT_PRO(300))];
    [self.view addSubview:self.totalView];
    [_totalView release];
    
    self.headImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0 , SCREEN_WIDTH, HEIGHT_PRO(250))];
    [self.totalView addSubview:self.headImage];
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:_singerPic] placeholderImage:[UIImage imageNamed:@"Read_zhanwei"]];
    [_headImage release];
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH_PRO(10), self.headImage.frame.size.height - HEIGHT_PRO(100), SCREEN_WIDTH - WIDTH_PRO(20), HEIGHT_PRO(20))];
    self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.font = [UIFont systemFontOfSize:20 weight:2];
    self.titleLabel.text = _singerName;
    [self.headImage addSubview:self.titleLabel];
    [_titleLabel release];
    
    
    self.ButtonView = [[UIView alloc] initWithFrame:CGRectMake(0, self.headImage.frame.size.height - HEIGHT_PRO(50), SCREEN_WIDTH, HEIGHT_PRO(50))];
    self.ButtonView.backgroundColor = [UIColor blackColor];
    self.ButtonView.alpha = 0.5;
    [self.headImage addSubview:self.ButtonView];
    [_ButtonView release];
    
    
    UIButton *songButton = [UIButton buttonWithType:UIButtonTypeCustom];
    songButton.frame = CGRectMake(0, self.headImage.frame.size.height - HEIGHT_PRO(50), SCREEN_WIDTH / 3, HEIGHT_PRO(50));
    songButton.tag = 1000;
    [self.headImage addSubview:songButton];
    
    UIButton *mvButton = [UIButton buttonWithType:UIButtonTypeCustom];
    mvButton.frame = CGRectMake(SCREEN_WIDTH / 3, songButton.frame.origin.y, SCREEN_WIDTH / 3, HEIGHT_PRO(50));
    mvButton.tag = 2000;
    [self.headImage addSubview:mvButton];
    
    UIButton *singerInfo = [UIButton buttonWithType:UIButtonTypeCustom];
    mvButton.frame = CGRectMake(SCREEN_WIDTH / 3 * 2, songButton.frame.origin.y, SCREEN_WIDTH / 3, HEIGHT_PRO(50));
    mvButton.tag = 3000;
    [self.headImage addSubview:singerInfo];
    
    
    
    
    
        
    self.playAllBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.playAllBtn.frame = CGRectMake(0, self.totalView.frame.size.height - HEIGHT_PRO(50) , SCREEN_WIDTH / 2, HEIGHT_PRO(50));
    [self.playAllBtn addTarget:self action:@selector(pushArrayData) forControlEvents:UIControlEventTouchUpInside];
    [self.totalView addSubview:self.playAllBtn];
    
    self.playImage = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH_PRO(20), HEIGHT_PRO(10), WIDTH_PRO(40), HEIGHT_PRO(40))];
    self.playImage.image = [UIImage imageNamed:@"Recognize_Play"];
    [self.playAllBtn addSubview:self.playImage];
    [_playImage release];
    
    self.playLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.playImage.frame.origin.x + self.playImage.frame.size.width + WIDTH_PRO(10), HEIGHT_PRO(15), WIDTH_PRO(100), HEIGHT_PRO(20))];
    self.playLabel.font = [UIFont systemFontOfSize:15];
    self.playLabel.text = @"播放全部";
    [self.playAllBtn addSubview:self.playLabel];
    [_playLabel release];
    
    self.tagLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.playLabel.frame.origin.x, self.playLabel.frame.origin.y + self.playLabel.frame.size.height , self.playLabel.frame.size.width, HEIGHT_PRO(20))];
    self.tagLabel.textColor = [UIColor grayColor];
    self.tagLabel.font = [UIFont systemFontOfSize:12];
    [self.playAllBtn addSubview:self.tagLabel];
    [_tagLabel release];
    
    
   
    
    
}

-(void)loadData
{
    [CustomerNetworking customerWithURL:[NSString stringWithFormat:@"http://api.dongting.com/song/singer/%@/songs?page=1&size=50&app=ttpod&v=v8.1.1.2015110616&user_id=0&mid=iPhone5S&f=f234&s=s310&imsi=&hid=&splus=9.1&active=1&net=2&openudid=e97c1f17f916efa173065a10152c7506e65b60f7&idfa=5FBD2BF5-1484-4C9B-A138-4D9CE22EADB5&utdid=VkKezJUW5SwDAGga0yzrZnyO&alf=700606&bundle_id=com.ttpod.music&latitude=38.89680989464323&longtitude=121.5286713817766", _singerID] andParamer:nil andBlock:^(id response) {
        
        for (NSDictionary *dic in [response objectForKey:@"data"]) {
            SongsModel *songsModel = [SongsModel modelWithDictionary:dic];
            [self.songsArray addObject:songsModel];
        }
        self.tagLabel.text = [NSString stringWithFormat:@"%ld首", _songsArray.count];
       
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
